package com.company.class8;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.company.class4.Washmachine;

import java.math.BigDecimal;

/**
 * @Classname JavaOBAndJson
 * @Description 类型说明
 * @Date 2022/5/2 18:04
 * @Created by zbw
 */

public class JavaOBAndJson {
    public static void main(String[] args) {
        //java中看到的内容，可以用toJSONString来进行转换
        Washmachine zbw = new Washmachine();
        String s = JSONObject.toJSONString(zbw);
        System.out.println(s);

        JSONObject jsonObject = JSON.parseObject(s);
        //json中的类型区分
        for(String key: jsonObject.keySet()){
            Object value = jsonObject.get(key);
            System.out.println("++++++++++++++++++++++++++++++++");
            System.out.println(key+"的值是"+value);

            if(value instanceof Integer){
                System.out.println(value+"是个整型");
            }else if(value instanceof String){
                System.out.println(value+"是个字符串型");
            }else if(value instanceof BigDecimal){
                System.out.println(value+"是个BigDecimal型");
            }else if(value instanceof JSONObject){
                System.out.println(value+"是个json对象");
            }else if(value instanceof JSONArray){
                System.out.println(value+"是个json数组");
            }
        }
    }
}
